package com.cy.controller;

import com.cy.domain.Goods;
import com.cy.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private IGoodsService IgoodsService;

    @RequestMapping("/findGoods")
    public String findGoods(Model model){
        List<Goods> list = IgoodsService.findGoods();
        model.addAttribute("list",list);
        return "goods";
    }



//    Rest风格  软件架构编码风格  url
    @RequestMapping("/deleteById/{id}")
    public String deleteById(@PathVariable Integer id){
        IgoodsService.deleteById(id);
        return "forward:/goods/findGoods";
    }



    @RequestMapping("/goodsInsertBack")
    public String goodsInsertBack(){
        return "goodsInsert";
    }
    @RequestMapping("/goodsInsertSubmit")
    public String goodsInsertSubmit(Goods goods){
        IgoodsService.insertObject(goods);
        return "forward:/goods/findGoods";
    }


    @RequestMapping("/updateById/{id}")
    public String updateById(@PathVariable Integer id,Model model){
        model.addAttribute("goods",IgoodsService.selectOne(id));
        return "goodsUpdate";
    }
    @RequestMapping("/goodsUpdateSubmit")
    public String goodsUpdateSubmit(Goods goods){
        IgoodsService.updateGoods(goods);
        return "forward:/goods/findGoods";
    }
}
